package day3;

import java.util.Scanner;

import org.junit.Test;
import org.junit.experimental.max.MaxCore;
import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID;

public class ArrayDemo {

	@Test
	public void test1() {
		int num = 3;
		int[] array = new int[4];
		array[0] = 23;
		array[1] = 3;
		array[2] = 4;
		array[3] = 24;
		System.out.println(array.length);
		
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
		
		for (int i = array.length - 1; i >= 0; i--) {
			System.out.println(array[i]);
		}
	}
	
	@Test
	public void test3() {
		int[] array1 = new int[3];
		double[] array2 = new double[3];
		boolean[] array3 = new boolean[3];
		char[] array4 = new char[3];
	}
	
	@Test
	public void test4() {
		//int[] array = {23, 4, 5};
		//int[] array = new int[] {23, 45, 6};
		
		int[] array = new int[4];
		array[0] = 23;
		array[1] = 3;
		array[2] = 4;
		array[3] = 24;
		int max = array[0];
		int min = array[0];
		for (int i = 1; i < array.length; i++) {
			if (array[i] > max) {
				max = array[i];
			}
			if (array[i] < min) {
				min = array[i];
			}
		}
		System.out.println("max: " + max);
		System.out.println("min: " + min);
	}
	
	
	@Test
	public void test55() {
		int[] array = new int[4];
		array[0] = 23;
		array[1] = 3;
		array[2] = 4;
		array[3] = 24;
		for (int i = 0; i <= array.length; i++) {
			System.out.println(array[i]);
		}
	}
	
	@Test
	public void test54() {
		int[] array = {40, 17, 21, 1};
		for (int i = 0; i < array.length - 1; i++) {
			if (array[i] > array[i + 1]) {
				int temp = array[i];
				array[i] = array[i + 1];
				array[i + 1] = temp;
			}
		}
		
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
	}
	
	@Test
	public void test77() {
		int[] array = {40, 17, 21, 1};
		// 外层循环控制比较多少趟，
		for (int i = 1; i <= array.length - 1; i++) {
			// 遍历整个数组，把最大值冒到最右边
			for (int j = 0; j < array.length - i; j++) {
				if (array[j] > array[j + 1]) {
					int temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
				}
			}
		}
		
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
	}
	
	@Test
	public void test2() {
		int[] array = new int[4];
		array[0] = 23;
		array[1] = 3;
		array[2] = 4;
		array[3] = 24;
		int max = getMax(array);
		System.out.println(max);
	}
	
	/**
	 * 传递一个整数类型的数组，返回数组的最大值
	 * @param array
	 * @return
	 */
	public int getMax(int[] array) {
		int max = array[0];
		for (int i = 0; i < array.length; i++) {
			if (array[i] > max) {
				max = array[i];
			}
		}
		
		return max;
	}
	
	@Test
	public void test88() {
		// char[] array = ['a' , 'b', 'c', 'b' , 'a'];
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();// "abcba"
		System.out.println(str);
		// Alt+Shfit+L
		char[] array = str.toCharArray();
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
	}
	
	
	
	
	
}
